﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using AvalonDock;
using Csla.Wpf;
using Itenso.Windows.Input;
using OpenExpressApp.Command;
using OpenExpressApp.MetaModel;
using OpenExpressApp.Module;
using OpenExpressApp.Module.WPF;
using OpenExpressApp.Module.WPF.Templete;
using OpenExpressApp.Template;
using OpenExpressApp.Types;

namespace OpenExpressApp.WPF.Templete
{
    /// <summary>
    /// Interaction logic for SelectForm.xaml
    /// </summary>
    public partial class QueryForm : WindowTemplateBase
    {
        private QueryFormController _controller;

        public QueryForm(Type boType, params Object[] getListParam)
            : base(boType)
        {
            InitializeComponent();

            this._controller = new QueryFormController(this, getListParam);
        }

        public override IFrameController Controller
        {
            get
            {
                return this._controller;
            }
        }

        public override ModuleType ModuleType
        {
            get
            {
                return ModuleType.Query;
            }
        }

        public override void LayoutQueryPanel()
        {
            bool navOnList = ApplicationModel.GetBusinessObjectInfo(this.RootEntityType).NavigateQueryRegionPoistion == QueryRegionPosition.ResultView;

            if (this.ListView.CondtionQueryView == null)
            {
                queryPane.Items.Remove(dcCondition);
            }

            if (this.ListView.NavigateQueryView == null || navOnList)
            {
                queryPane.Items.Remove(dcNavigate);
            }

            if (this.ListView.CondtionQueryView == null && (this.ListView.NavigateQueryView == null || navOnList))
            {
                resizingPanel.Children.Remove(queryPane);
            }

            //自动隐藏查询面板
            if (ApplicationModel.GetBusinessObjectInfo(this.RootEntityType).AutoHideQueryPane)
            {
                queryPane.GetManager().ToggleAutoHide(queryPane);
            }
        }

        public override object GetRegion(string regionName)
        {
            switch (regionName)
            {
                case ViewRegionNames.ListRegion:
                    return dpQuery;
                case ViewRegionNames.ConditionQueryRegion:
                    return conditionQueryRegion;
                case ViewRegionNames.NavigateQueryRegion:
                    return navigateQueryRegion;
                case ViewRegionNames.MainToolBar:
                    return mainToolBar;
                default:
                    return null;
            }
        }
    }
}
